package es.cazadoresmadridejos.beans.facade.location;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;

import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.directwebremoting.spring.SpringCreator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import es.cazadoresmadridejos.beans.manager.city.CityManager;
import es.cazadoresmadridejos.beans.manager.province.ProvinceManager;
import es.cazadoresmadridejos.model.City;

@Service
@RemoteProxy(name="locationFacade",creator=SpringCreator.class)
public class LocationFacade {

	@Autowired private CityManager cityManager;
	@Autowired private ProvinceManager provinceManager;
	
	public LocationFacade(){
		super();
	}
	
	@RemoteMethod
	public List<City> findCitiesByProvince(Long id){
		return cityManager.findByProvince(id);
	}
	
	public String executeUrl(String url) throws ServletException, IOException{
		WebContext context = WebContextFactory.get();
		return context.forwardToString(url);
	}
	
	
}
